package server.session.handler;

import server.session.UserSession;
import unit.request.LoginRequest;
import unit.request.Request;
import unit.response.LoginRequestResponse;

import java.io.IOException;

/**
 * @author Yuri Denison
 * @since 07.08.11
 */
public class LoginRequestHandler implements RequestHandler {
    @Override
    public void handleRequest(Request request, UserSession userSession) {
        LoginRequest loginRequest = (LoginRequest) request;
        userSession.setUserId(userSession.getDataStorage().getUserID(loginRequest.getLogin(), loginRequest.getPassword()));
        userSession.setOnline();
        LoginRequestResponse response = new LoginRequestResponse(request.getRequestID(), userSession.getSession(), userSession.getUserId());
        try {
            userSession.getConnector().send(response);
        } catch (IOException e) {
            e.printStackTrace();
        }
    }
}
